#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>


int main()
{
    int fd = open("atomic.c", O_RDONLY);
    if (fd == -1)
    {
        fprintf(stderr, "%d %s", errno, strerror(errno));
        return 1;
    }
    
    uint32_t strLen;
    ssize_t r = read(fd, &strLen, sizeof(strLen));
    if (r == -1)
    {
        fprintf(stderr, "can't read file: %s", strerror(errno));
        return 1;
    }
    
    char* buf = malloc(strLen + 1);
    if (r == -1)
    {
        fprintf(stderr, "can't read file: %s", strerror(errno));
        return 1;
    }
    
    buf[strLen] = '\0';
    
    printf("string: %s\n", buf);
    
    free(buf);
    
    return 0;
}